package cn.yang.domain.strategy.service.rule.tree.factory;

import cn.yang.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import cn.yang.domain.strategy.model.valobj.RuleTreeVO;
import cn.yang.domain.strategy.service.rule.tree.ILogicTreeNode;
import cn.yang.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import cn.yang.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @version v1.0
 * @ClassName: cn.yang.domain.strategy.service.rule.tree.factory
 * @Description: 规则树工厂
 * @Author: YJ
 */
@Service
public class DefaultTreeFactory {
    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;

    /**
     * 构造函数
     * 通过依赖注入（通常由Spring框架完成）传入一个包含所有逻辑节点实现的Map
     * @param logicTreeNodeGroup
     */
    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    /**
     * 创建规则树引擎，打开/创建一个逻辑树
     * @param ruleTreeVO
     * @return
     */
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        private StrategyAwardVO strategyAwardVO;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        //抽奖奖品ID - 内部流转使用
        private Integer awardId;
        //抽奖奖品规则
        private String awardRuleValue;
    }
}
